// -rnCDDlg.h : header file
//

#pragma once


#include "FileListBox.h"
#include "MatrixStatic.h"
#include "ScsiCommand.h"
#include "Wizard.h"
#include "Exports.h"
#include "DiscRecorder.h"
#include "ImageButtonWithStyle.h"
#include "resource.h"
#include <vector>
#include <time.h>
using namespace std ;
// CBurnCDDlg dialog
class CBurnCDDlg : public CDialogEx
{
// Construction
public:
	CBurnCDDlg(CWnd* pParent = NULL);	// standard constructor
	DWORD_PTR	GetSpeedSecsPerSecond(IMAPI_MEDIA_PHYSICAL_TYPE mediaType);
	int			isMediaBlank();
	CComboBox	m_VerifyCombo;
	int			m_argc;
	CString 	m_argv;
// Dialog Data
	enum { IDD = IDD_BURNCD_DIALOG };
// Generated message map functions
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	virtual BOOL OnInitDialog();
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual LRESULT OnTray(WPARAM wParam, LPARAM lParam);


DECLARE_MESSAGE_MAP()	
	afx_msg void OnCbnSelchangeDeviceCombo();
	afx_msg void OnLbnSelchangeBurnFileList();
	afx_msg void OnBnClickedAddFilesButton();
	afx_msg void OnBnClickedAddFolderButton();
	afx_msg void OnDestroy();
	afx_msg void OnBnClickedBurnButton();
	afx_msg LRESULT OnImapiUpdate(WPARAM, LPARAM);
	afx_msg LRESULT OnImapiAudioUpdate(WPARAM, LPARAM);
	afx_msg LRESULT OnImapiRawUpdate(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnImapiFsUpdate(WPARAM, LPARAM);
	afx_msg LRESULT OnBurnStatusMessage(WPARAM, LPARAM);
	afx_msg LRESULT OnBurnFinished(WPARAM, LPARAM);
	CString GraphData_CalculateCRC(UCHAR *buffer,  int len);
	DWORD	CalculateCRC(UCHAR *Buffer, DWORD Length);
	int		axtoi(const TCHAR *value);
	afx_msg LRESULT OnEraseFinished(WPARAM, LPARAM);
	afx_msg void OnBnClickedRemoveFilesButton();
	afx_msg void OnDropFiles(HDROP hDropInfo);
	afx_msg void OnClickedRadioburnfiles();
	afx_msg void OnRadioburniso();
	afx_msg void OnClickedErase();
	afx_msg void OnClose();
	afx_msg void OnClickedButtonEject();
	afx_msg void OnSelchangeComboUdfRev();
	afx_msg void OnSelchangeComboMediaSpeeds();
	afx_msg void OnClickedCheckBurnproof();
	afx_msg void OnSelchangeComboFilesystem();
	afx_msg void OnClickedEjectWhenFinished();
	afx_msg void OnClickedButtonRemoveall();
	afx_msg void OnClickedCloseMediaChk();
	afx_msg void OnClickedCheckMultisession();
	afx_msg LRESULT OnUpdateData (WPARAM, LPARAM);
	afx_msg void OnClickedCheckBootimage();
	afx_msg void OnClickedButtonSave();
	afx_msg void OnClickedButtonLoad();
	afx_msg void OnFolderUp();
	afx_msg void OnFolderdown();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnClickedCheckFullerase();
	afx_msg void OnSelchangeComboVerify();
	afx_msg void OnClickedCheckShutdownwhencomplete();
	afx_msg void OnClickedUpdateButton();
	afx_msg void OnSelchangeComboIsomode();
	afx_msg void OnClickedHelpbutton();
	afx_msg void OnClickedButtonWizard();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnMenuToolsSettings();
	afx_msg void OnHelpDvdinfoproburnerontheweb();
	afx_msg void OnHelpAboutdvdinfoproburner();
	afx_msg LRESULT OnSystemTray(WPARAM wParam, LPARAM lParam);  //my own dont put inside AFX_MSG
	afx_msg void OnClickedIsodisc();
	afx_msg void OnChangeEditCopies();
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	
// Implementation
protected:
	HICON m_hIcon;
	HICON m_addfile;
	HICON m_update;
	HICON m_delete;
	HICON m_deleteall;
	HICON m_eject;
	HICON m_save;
	HICON m_burn;
	HICON m_erase;
	HICON m_load;
	HICON m_up;
	HICON m_down;
	HICON m_stop;
	HICON m_help;
	HICON m_wizard;
	HICON m_isodisc;
	HICON m_saveibg;

	static UINT __cdecl BurnThread(LPVOID pParam);
	static UINT __cdecl WriteISOThread(LPVOID pParam);
	static UINT __cdecl WriteBinThread(LPVOID pParam);
	static UINT __cdecl WriteISOHddThread(LPVOID pParam);
	static UINT __cdecl EraseThread(LPVOID pParam);
	static UINT __cdecl AudioThread(LPVOID pParam);
	static UINT __cdecl AudioDAOThread(LPVOID pParam);
	static UINT __cdecl CreateISOFromDiscThread(LPVOID pParam);
	static UINT __cdecl AddRecordersToComboBoxThread(LPVOID pParam);
	static bool CreateMediaFileSystem(CBurnCDDlg* pThis, IMAPI_MEDIA_PHYSICAL_TYPE mediaType, IStream** dataStream, FsiFileSystems nFileSystem, LONG UDFVersion, VARIANT_BOOL varbool, SAFEARRAY* multiSession);
	static bool CreateFileSystemForISO(CBurnCDDlg* pThis, IStream** ppDataStream, FsiFileSystems nFileSystem, LONG UDFVersion);
	
	LRESULT		OnCreateThumbToolBar (WPARAM, LPARAM);

public:
	CButton m_bMulti;
	CButton m_CheckBootable;
	CButton m_CheckShutdown;
	CButton m_ejectWhenFinished;
	CButton m_closeMedia;
	CButton m_BurnProof;
private:
	CImageButtonWithStyle m_AddFile;
	CImageButtonWithStyle m_Add_Folder;
	CImageButtonWithStyle m_DeleteFile;
	CImageButtonWithStyle m_Delete_All;
	CImageButtonWithStyle m_Eject;
	CImageButtonWithStyle m_Save;
	CImageButtonWithStyle m_Burn;
	CImageButtonWithStyle m_Erase;
	CImageButtonWithStyle m_Load;
	CImageButtonWithStyle m_Down;
	CImageButtonWithStyle m_Up;
	CImageButtonWithStyle m_Help;
	CImageButtonWithStyle m_Update;
	CImageButtonWithStyle m_Wizard;
	CImageButtonWithStyle m_Isodisc;
	CImageButtonWithStyle m_SaveIBG;
	CButton m_StaticListWindow;
	CEdit m_NumberofCopies;
	CStatic m_TotalSizeText;
	CStatic m_bufferText;
	CStatic m_maxText;
	CStatic m_progressTrackText;
	CStatic m_progressText;
	CSpinButtonCtrl m_SpinNCopies;
	
	ITaskbarList3* m_pTaskbarList;
	CComboBox m_deviceComboBox;
	CComboBox m_UDFRevision;
	CComboBox m_FileSystemCombo;
	CComboBox m_MediaSpeeds;
	CFileListBox m_fileListbox;
//	CMatrixStatic m_estimatedTime;
//	CMatrixStatic m_timeLeft;
	CProgressCtrl m_progressCtrl;
	CProgressCtrl m_bufferCtrl;
	CProgressCtrl m_capacityProgress;
	CString m_volumeLabel;


	CScsiCommand		cdb;

	IDiscFormat2Data* pIDiscFormatData;
	IDiscFormat2Erase* pIDiscFormatErase;
	CToolTipCtrl	m_pToolTip;
	CProgressCtrl m_ProgressTrack;
	CCriticalSection m_critSection;
	IMAPI_MEDIA_PHYSICAL_TYPE m_CurrentMediaBurning;


	typedef vector<float> FLOATVECTOR;
	typedef vector<long> LONGVECTOR;
	
	FLOATVECTOR SpeedVector;
	LONGVECTOR SectorVector;
	LONGVECTOR RateVector;
	LONGVECTOR BufferVector;
	FLOATVECTOR CPUVector;
  
    clock_t start, end;
    float cpu_time_used;

	// Iterator is used to loop through the vector.
	FLOATVECTOR::iterator iSpeedVector;
	LONGVECTOR::iterator iSectorVector;
	LONGVECTOR::iterator iRateVector;
	LONGVECTOR::iterator iBufferVector;
	FLOATVECTOR::iterator iCPUVector;

private:	
	
	IMAPI_MEDIA_PHYSICAL_TYPE GetCurrentMediaType();
	HRESULT		GetSupportedWriteSpeeds(IMAPI_MEDIA_PHYSICAL_TYPE *pMediaType, SAFEARRAY** pVal);
	HRESULT		GetSupportedWriteSpeedDescriptors(IMAPI_MEDIA_PHYSICAL_TYPE *pMediaType, SAFEARRAY** pVal);
	BOOL		doesNameExistinList(CString *folder);
	void		FillSpeedsComboBox();
	LONG		GetSpeedDivisor(LONG MediaType);
	void		InitToolTips();
	
	LONG		GetUDFRevision();
	char		FirstDriveFromMask (ULONG unitmask);
	void		SetLastSelectedDrive();
	void		SelectDriveFromArgument(CString* str);
	void		EjectDrive();
	BOOL		GetBufferUnderrunEnabled();
	BOOL		SetBufferUnderrunMode(VARIANT_BOOL set);
	void		ShutDownWindows();
	void		GetImapiErrorString(int error, CString *errorstr);
   void			SetCancelBurning(bool bCancel);
	bool		GetCancelBurning();
	void		SetCancelErasing(bool bCancel);
	bool		GetCancelErasing();
	void		SetCancelISOFromDisc(bool bCancel);
	CString		GetMediaTypeString(int mediaType);
	ULONGLONG	GetBDLayer0End();
	ULONGLONG	GetDVDLayer0End();
	LONGLONG	GetBDMaxLBA();
	ULONGLONG	GetLayer0End();
	void		ClearListControl();
	void		UpdateCapacity(BOOL bQuiet=FALSE);
	void		EnableBurnButton();
	void		GetParentFolderName(CString *filename);
	void		EnableUI(BOOL bEnable);
	BOOL		isDirectory(LPCTSTR szPath);
	void		DeleteItem(int index);
	void		SetWaitCursor(BOOL on);
	void		SetISOBurn();
	int			GetFileSystem();
	int			isMediaLoaded();
	BOOL		GetVolumeName();
	BOOL		GetVolumeName(CString* str);
	HRESULT  	GetMediaState(IMAPI_FORMAT2_DATA_MEDIA_STATE* state);
	void		FillUDFRevisionsCombo();
	void		SaveIBBFile(CString *cFileName);
	int			ConvertMP3toWAV(CString* infile,  CString* outfile);
	SAFEARRAY*	GetSupportedUDFRevisions();
	HRESULT		GetDiscRecorder(ULONG index, IDiscRecorder2 ** recorder);
	void		UpdateTimes(LONG totalTime, LONG remainingTime, ULONG writtenSectors=0, ULONG totalSectors=0);
	void		UpdateVerifyTimes(LONG totalTime, LONG remainingTime, ULONG writtenSectors=0, ULONG totalSectors=0);
	
	void		UpdateBuffer(LONG usedSystemBuffer, LONG totalSystemBuffer);
	void		UpdateAudioBuffer(LONG usedSystemBuffer, LONG totalSystemBuffer);
	
	void		UpdateProgress(ULONG writtenSectors, ULONG totalSectors);
	void		UpdateAudioProgress(ULONG writtenSectors, ULONG totalSectors, ULONG currentTrack);
	void		UpdateVerifyProgress(ULONG writtenSectors, ULONG totalSectors);
	void		UpdateEraseProgress(ULONG elapsedseconds, ULONG totalSeconds);
	void		UpdateFSProgress(BSTR currentFile, ULONG copiedSectors, ULONG totalSectors);

	bool		GetCancelAudioBurning();
	void		SetCancelAudioBurning(bool bCancel);
	LONG		GetFreeSectors(void);
	LONG		GetTotalSectors(void);
	void		PlayCompletedSound();
	void		PlayStartupSound();
	void		GetDisplayColors();
	__int64		FileSize64(CString* szFileName);
	void		FormatNumber1024(double bytes, LPTSTR buffer, int bufsize);
	void		DoNextCopy();
	void		StartNextCopy();
	void		DoWizard(BOOL bFromButton);
	void		ChangeDeviceCombo();
	void		SetBackgroundColor();
	HRESULT		GetCDImageCreatorInterface(IRawCDImageCreator** raw);
	void		RemoveTrayIcon();
	void		AddSystemTrayIcon();
	void		DeleteStatusAreaBalloon();
	void		ShowStatusAreaBalloon(char *string);
	CString		GetDiscStateString(IMAPI_FORMAT2_DATA_MEDIA_STATE state);
	void		SetFonts();
	void		SetIcons();
	void		SetControlDefaults();
	void		CalcElapsedTime(SYSTEMTIME * StartTime, SYSTEMTIME * FinishTime, SYSTEMTIME * ElapsedTime);
	DWORD		GetSecondsElapsed(SYSTEMTIME * StartTime, SYSTEMTIME * EndTime);
	void		GetMediaMidCode(CString *midcode);
	void		SaveGraphData();
	BOOL		SetInstallDirectory();
	void		InitGraphDataVariables();
private:
	BOOL b102; 
	BOOL b150; 
	BOOL b200; 
	BOOL b201; 
	BOOL b250; 
	BOOL b260;
	
	CFont mFont;
//	BOOL m_closeMedia;
//	BOOL m_ejectWhenFinished;
	
	bool	m_isCdromSupported;
	bool	m_isDvdSupported;
	bool	m_isDualLayerDvdSupported;
	bool    m_isBDSupported;
	bool    m_isHDDVDSupported;
	bool	m_cancelBurn;
	bool	m_cancelaudioBurn;
	bool    m_cancelErase;
	bool	m_cancelISOFromDisc;
	bool    m_bWaitingForDisc;
	bool    m_addingdrives;
	bool	m_oversizequestion;
	BOOL	m_hasWav;
	int		m_selectedMediaType;
	int		m_nCurrentMode;
	bool   m_BurnButtonClicked;

	bool    isDvdBurn, isBDROMBurn, isRedBookBurn, isDataBurn;
	BOOL    m_volumelabelchanged;
	LONG  m_divisor;
	COleDateTimeSpan  m_ElapsedTime;
	COleDateTime	m_ElapsedStartTime;
	double  uwrittenSectors;

	COleDateTime m_BurnStartTime, m_BurnLastTime;
	long m_LastWrittenSectors;
	BOOL m_start;
	int m_RadioBurnFilesFolders;
	int m_nAutoFileSystem;
	int m_AutoUDFVersion;
	int m_WizardMode;
	int m_nNumberofCopies;
	CString ISOfile;
	CString ISOSaveFolder;
	CString m_mediaTypeEdit, m_cBootFileName;
	CString m_BootImageFile;
	CWizard *WizardDlg;
	CString m_Progresstext;
	CString m_midcode;
	IMAPI_MEDIA_PHYSICAL_TYPE m_mediatype;
	CString m_cmediatype;
	CString m_MaxSpeed, m_SelectedSpeed;
	
	ULONGLONG m_datasectors;
	ULONGLONG m_MediaCapacity;
	ULONGLONG m_LayerBreak;
	ULONGLONG m_TotalSizeToBurn;
	ULONGLONG m_TotalSizeFree;
	LONG m_TotalAudioTracks;
	LONG m_TotalSectorsOnMedia;
	ULONG back, on, off;




public:
//	afx_msg void OnSelchangeComboRotation();
//	CComboBox m_Rotation;
	afx_msg void OnClickedCheckUsecav();
	CButton m_CheckUseCAV;
	CString m_mediaTypeEdit2;
	afx_msg void OnClickedButtonSaveibg();
	
	afx_msg void OnChangeVolume();
};

